#ifndef _HEADERS_H_
#define _HEADERS_H_

#include <winsock2.h>  // This must be included before "windows.h"
#include <windows.h>

/* Ethernet header */
typedef struct eth_header{
	u_char  dmac[6];
	u_char  smac[6];
	u_short type;
}eth_header;

/* ARP header */
typedef struct arp_header{
	u_short hw_type;
	u_short prot_type;
	u_char  hw_size;
	u_char  prot_size;
	u_short option;
	u_char  smac[6];
	u_char  sip[4];
	u_char  dmac[6];
	u_char  dip[4];
}arp_header;

/* IPv4 header */
typedef struct ip_header{
    u_char  ver_ihl;        // Version (4 bits) + Internet header length (4 bits)
    u_char  tos;            // Type of service 
    u_short length;         // Total length 
    u_short identification; // Identification
    u_short flags_fo;       // Flags (3 bits) + Fragment offset (13 bits)
    u_char  ttl;            // Time to live
    u_char  protocol;       // Protocol
    u_short checksum;       // Header checksum
    u_char  saddr[4];       // Source address
	u_char  daddr[4];       // Destination address
}ip_header;

/* Pseudo IPv4 header */
typedef struct psd_header
{
    u_char    saddr[4];
    u_char    daddr[4];
    u_char    zero;
    u_char    protocol;
    u_short   length;
}psd_header;

/* ICMPv4 header */
typedef struct icmp_header {
	u_char  type;
	u_char  code;
	u_short checksum;
	u_short id;
	u_short sequence;
}icmp_header;

/* IPv6 header */
typedef struct ip6_header{
	u_char    ver_pri;
	u_char    flowlbl[3];
	u_short   payload;     // payload length (without header length)
	u_char    nexthdr;
	u_char    hoplimit;
	u_char    saddr[16];   // 128 bits source address
	u_char    daddr[16];   // 128 bits destination address
}ip6_header;

/* Pseudo IPv6 header */
typedef struct psd6_header{
    u_char    saddr[16];
    u_char    daddr[16];
    u_short   length[2];
    u_char    zero[3];
    u_char    nexthdr;
}psd6_header;

/* ICMPv6 header */
typedef struct icmp6_header {
	u_char  type;
	u_char  code;
	u_short checksum;
	u_short id;
	u_short sequence;
}icmp6_header;

/* TCP header */
typedef struct tcp_header{
	u_short   srcport;   // 16 bits source port
	u_short   destport;  // 16 bits destination port
	u_long    seq;
	u_long    ack;
	u_char    len_res;
	u_char    flag;
	u_short   window;
	u_short   checksum;  // 16 bits checksum
	u_short   urp;
}tcp_header;

/* UDP header*/
typedef struct udp_header{
    u_short sport;          // Source port
    u_short dport;          // Destination port
    u_short length;         // Datagram length
    u_short checksum;       // Checksum
}udp_header;

/* Protocol constants */

#define ETH_IP         0x0800
#define ETH_IP6        0x86dd
#define ETH_ARP        0x0806

#define ARP_REQUEST    0x0001
#define ARP_REPLY      0x0002

#define IP_ICMP             1
#define IP_TCP              6
#define IP_UDP             17
#define IP_ICMP6           58

#define ICMP_ECHO           8
#define ICMP_ECHO_REPLY     0

#define ICMP6_ECHO        128
#define ICMP6_ECHO_REPLY  129

#endif // _HEADERS_H_